﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace EFong.Contract
{
    [DataContract]
    public class Role
    {
        public Role() 
        { 
            ID = Guid.NewGuid();
            Authorities = new List<RoleAuthorizedItem>();
            Effective = true;
        }

        private Guid _id = Guid.NewGuid();
        [DataMember]
        public Guid ID
        {
            get { return _id; }
            set { _id = value; }
        }

        private bool _effective = true;
        [DataMember]
        public bool Effective
        {
            get { return _effective; }
            set { _effective = value; }
        }

        private string _name = string.Empty;
        [DataMember]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private List<RoleAuthorizedItem> _authorities = new List<RoleAuthorizedItem>();
        [DataMember]
        public List<RoleAuthorizedItem> Authorities
        {
            get { return _authorities; }
            set { _authorities = value; }
        }

        public override string ToString()
        {
            return Name;
        }

        public override bool Equals(object obj)
        {
            Role temp = obj as Role;
            if (temp == null)
                return false;
            return (this.ID.Equals(temp.ID));
        }
    }
}
